<template>
	<view class="main_bg">
		<app-headerIndex title="简易报修" :isBack="false" bgColor="#fff" :titleStyle="{color:'#000'}"></app-headerIndex>
		<view class="cell-group">
			<view class="flex-col">
				<view class="flex-item">
					<view class="label_title">设备名称</view>
					<navigator url='/pages/user/device_list' hover-class="none">
						<view style="background: #F5F5F5;border-radius: 20rpx;padding: 15rpx 40rpx;display: flex;">
							{{query.device_name || '请选择'}}<u-icon name="arrow-right"></u-icon>
						</view>
					</navigator>
				</view>
				<view class="flex-item">
					<view class="label_title">规格</view>
					<input class="input" type="text" placeholder="请输入" v-model="query.device_spec" />
				</view>
				<view class="flex-item">
					<view class="label_title">故障描述</view>
					<view class="textarea">
						<textarea placeholder="请输入" v-model="query.describe" />
						<app-upload v-model="query.store_imgs" :value="query.store_imgs" accept="media" multiple
							:maxCount="9" />
					</view>
				</view>
			</view>
		</view>
		<view class="submit-btn" @click="addRepair">提交</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				query: {
					device_name: "",
					device_spec: "",
					describe: "",
					store_imgs: ""
				},
				name: ''
			}
		},
		created() {
			this.deviceSearch()
			
		},
		mounted() {
			uni.$on('device_item', val => {
				console.log(val)
				this.query.device_name = val.device_name
				this.query.device_id = val.id
			})
		},
		beforeDestroy() {
			uni.$off('device_item')
		},
		methods: {
			addRepair() {
				this.$http.post('/data/api.auth.Device/addRepair', this.query).then(res => {
					this.query = {
						device_name: "",
						device_spec: "",
						describe: "",
						store_imgs: ""
					}
					uni.showToast({
						icon: "success",
						title: "提交成功",
						mask: true,
					})
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.main_bg {
		padding: 30rpx 20rpx;
	}

	.cell-group {
		border-radius: 20rpx;
		background: white;
		padding: 42rpx 48rpx;
	}

	.flex-col {
		display: flex;
		flex-direction: column;
		gap: 32rpx;

		.flex-item {
			display: flex;
			flex-direction: column;
			gap: 16rpx;
		}

		.label_title {
			font-size: 32rpx;
			color: #333;
		}

		.input,
		.textarea {
			background: #F5F5F5;
			border-radius: 20rpx;
			padding: 15rpx 40rpx;
		}

		textarea {
			width: 100%;
			height: 150rpx;
		}

	}

	.submit-btn {
		background-color: #4F6FF6;
		border-radius: 10rpx;
		font-size: 28rpx;
		color: #ffffff;
		text-align: center;
		padding: 26rpx 0;
		width: 80%;
		margin: 80rpx auto;
	}
</style>